#define _CRT_SECURE_NO_WARNINGS
#define include
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
struct Stu
{
	char name[20];
	int chinese;
	int english;
	int math;
};
int main() {
	int n = 0;
	int i = 0;
	int j = 0;
	int count[100] = {};
	scanf("%d", &n);
	Stu students[100] = {};
	for (i = 0; i < n; i++)
	{
		char* p1 = students[i].name;
		for ( j = 0; j < 20; j++)
		{
			scanf("%c", p1 + j);
			if ((*(p1+j))==' ')
			{
				*(p1 + j) = '\0';
				break;
			}
		}
		scanf("%d", &students[i].math);
		scanf("%d", &students[i].chinese);
		scanf("%d", &students[i].english);
	}
	for ( i = 0; i < n; i++)
	{
		count[i] = students[i].math + students[i].chinese + students[i].english;
	}
	for (i = 0; i < n-1; i++)
	{
		int a = 0;
		Stu b = {};
		for (j = 0; j < n-1; j++)
		{
			if (count[j]>count[j+1])
			{
				a = count[j];
				count[j] = count[j + 1];
				count[j + 1] = a;
				b = students[j];
				students[j] = students[j + 1];
				students[j + 1] = b;
			}
		}
	}
	for ( i = 0; i < n; i++)
	{
		char* p = students[i].name;
		int sz = strlen(students[i].name);
		for (j = 0; j < sz; j++)
		{
			printf("%c", *(p+j));
		}
		printf("%d", count[i]);
		printf("\n");
	}
}